//
// loi.cpp for 203poisson in /home/morel_t//Rendu/maths/203poisson
// 
// Made by thomas morel
// Login   <morel_t@epitech.net>
// 
// Started on  Tue Mar 20 18:42:05 2012 thomas morel
// Last update Fri Mar 23 15:09:44 2012 florian jousseau
//

#include	<cmath>
#include	"203poisson.hh"
#include	<stdlib.h>
#include	<iostream>

double		combinaison(int n, int k)
{
  if (k >= n)
    {
      std::cout << "<k> is too big." << std::endl;
      exit(1);
    }
  double	numerator = factorial(n);
  double	denominator = factorial(k);

  denominator *= factorial(n - k);
  return (numerator / denominator);
}

double		loi_binomiale(int n, int k, double p)
{
  double	combi = combinaison(n, k);
  double	exp_p = pow(p, k);
  double	exp_pc = pow(1 - p, n - k);

  return (combi * exp_p * exp_pc);
}

double		loi_poisson(int k, double l)
{
  double	exp_l = exp(-l);
  double	pow_l = pow(l, k);
  double	fact_k = factorial(k);

  return ((exp_l * pow_l) / (fact_k));
}
